package com.taotao.springboot2.example.enums;

import com.taotao.springboot2.common.RespData;
import com.taotao.springboot2.common.enumhub.CodeTextEnumView;
import com.taotao.springboot2.common.enumhub.EnumHub;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.time.LocalDateTime;
import java.util.List;

import static org.springframework.web.bind.annotation.RequestMethod.GET;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author saytime
 * @since 2018-12-06
 */
@Api(tags="枚举演示")
@RestController
@RequestMapping("/")
public class EnumController {


    @ApiOperation(value = "查询枚举下拉框",notes = "")
    @RequestMapping(value = "/emumList", method = GET)
    public List<CodeTextEnumView> emumList(@RequestParam(value="enumId",required = false,defaultValue = "HobyEnum") String enumId) {

        return EnumHub.getCodeTextEnumViewList(enumId);
    }



    @ApiOperation(value = "枚举名称显示",notes = "")
    @RequestMapping(value = "/enumName", method = RequestMethod.GET)
    public RespData<PersonDTO> enumName() {
        PersonDTO p = new PersonDTO();
        p.setAge(30);
        p.setName("mikesrytryeruututututtu");
        p.setBirthday(LocalDateTime.now());
        p.setHoby(HobyEnum.basketball.getCode());

        return RespData.successResp(p);
    }

    @ApiOperation(value = "枚举扩展名称显示",notes = "")
    @RequestMapping(value = "/mask", method = RequestMethod.GET)
    public RespData<PersonDTO> mask() {
        PersonDTO p = new PersonDTO();
        p.setAge(30);
        p.setName("mikesrytryeruututututtu");
        p.setBirthday(LocalDateTime.now());
        p.setHoby("chess");

        return RespData.successResp(p);
    }



    @ApiOperation(value = "枚举校验",notes = "")
    @RequestMapping(value = "/enumValid", method = RequestMethod.POST)
    public RespData<Object> enumValid(@Valid @RequestBody PersonDTO p) {

        return RespData.successResp();
    }

}
